<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改主机信息')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-post-edit" th:object="${info}">
			<input id="id" name="id" type="hidden" th:field="*{id}"/>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">节点编号：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="nodeCode" id="nodeCode" th:field="*{nodeCode}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">主机名：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="hostname" id="hostname" th:field="*{hostname}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">IP地址：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="ip" id="ip" th:field="*{ip}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">访问端口：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="port" id="port" th:field="*{port}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">健康检查请求地址：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="healthCheckUrl" id="healthCheckUrl" th:field="*{healthCheckUrl}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">运行信息请求地址：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="serverInfoUrl" id="serverInfoUrl" th:field="*{serverInfoUrl}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">执行命令地址：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="execUrl" id="execUrl" th:field="*{execUrl}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">检测软件存活的请求地址：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="isAliveUrl" id="isAliveUrl" th:field="*{isAliveUrl}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">时间同步信息请求地址：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="timeSyncUrl" id="timeSyncUrl" th:field="*{timeSyncUrl}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">操作系统：</label>
				<div class="col-sm-8">
					<select name="operatingSystem" class="form-control m-b" th:with="type=${@dict.getType('operating_system')}">
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{operatingSystem}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">远程操作端口：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="sshPort" id="sshPort" value="22">
					<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 远程启动和停止监控代理的端口目前只支持SSH</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required" title="启动monitor-agent的脚本路径">启动监控代理脚本路径：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="startupScriptPath" id="startupScriptPath" th:field="*{startupScriptPath}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required" title="停止monitor-agent的脚本路径">停止监控代理脚本路径：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="stopScriptPath" id="stopScriptPath" th:field="*{stopScriptPath}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">是否自启：</label>
				<div class="col-sm-8">
					<label class="toggle-switch switch-solid">
						<input type="checkbox" id="selfStart" th:checked="*{selfStart != 0}">
						<span></span>
					</label>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">监控状态：</label>
				<div class="col-sm-8">
					<label class="toggle-switch switch-solid">
						<input type="checkbox" id="status" th:checked="*{status != 0}">
						<span></span>
					</label>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<textarea id="remark" name="remark" class="form-control">[[*{remark}]]</textarea>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		var prefix = ctx + "system/node";
		
		$("#form-post-edit").validate({
			onkeyup: false,
			rules:{
				nodeCode:{
					digits:true,
					remote: {
						url: prefix + "/checkNodeCodeUnique",
						type: "post",
						dataType: "json",
						data: {
							"id" : function() {
								return $("#id").val();
							},
							"nodeCode" : function() {
								return $.common.trim($("#nodeCode").val());
							}
						},
						dataFilter: function(data, type) {
							return $.validate.unique(data);
						}
					}
				},
				ip:{
					ip:true,
					remote: {
						url: prefix + "/checkIpUnique",
						type: "post",
						dataType: "json",
						data: {
							"id": function() {
								return $("#id").val();
							},
							"ip" : function() {
								return $.common.trim($("#ip").val());
							}
						},
						dataFilter: function(data, type) {
							return $.validate.unique(data);
						}
					}
				},
				port:{
					digits:true,
					range:[0,65535]
				},
				sshPort:{
					digits:true,
					range:[0,65535]
				},
			},
			messages: {
				"ip": {
					remote: "IP地址已经存在"
				},
				"nodeCode": {
					remote: "节点编码已经存在"
				}
		    },
		    focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
				let data = $('#form-post-edit').serializeArray();
				var selfStart = $("input[id='selfStart']").is(':checked') == true ? 1 : 0;
				var status = $("input[id='status']").is(':checked') == true ? 1 : 0;
				data.push({"name": "status", "value": status});
				data.push({"name": "selfStart", "value": selfStart});
				$.operate.save(prefix + "/edit", data);
	        }
	    }
	</script>
</body>
</html>
